package Time_Clock;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

class Time {
    private int hour;
    private int minute;
    private int second;

    Time() {
        setCurrentTime();
    }

    Time(long elapsed_time) throws ParseException {//specified elapsed time since midnight, Jan 1, 2002, in milliseconds
        setTime(elapsed_time);
    }

    Time(int hour, int minute, int second) {
        this.hour = hour;
        this.minute = minute;
        this.second = second;
    }

    void setCurrentTime(){
        Calendar calendar = Calendar.getInstance();
        hour = calendar.get(Calendar.HOUR_OF_DAY);
        minute = calendar.get(Calendar.MINUTE);
        second = calendar.get(Calendar.SECOND);
    }

    void setTime(long elapsed_time) throws ParseException {
        Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2002-01-01");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.setTimeInMillis(calendar.getTimeInMillis() + elapsed_time);
        hour = calendar.get(Calendar.HOUR_OF_DAY);
        minute = calendar.get(Calendar.MINUTE);
        second = calendar.get(Calendar.SECOND);
    }

    void setHour(int hour) {
        this.hour = hour;
    }

    void setMinute(int minute) {
        this.minute = minute;
    }

    void setSecond(int second) {
        this.second = second;
    }

    int getHour() {
        return hour;
    }

    int getMinute() {
        return minute;
    }

    int getSecond() {
        return second;
    }

    public String toString() {
        return hour + " : " + minute + " : " + second;
    }
}